package com.hk.login;

import java.sql.Timestamp;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.hk.action.Action;
import com.hk.action.ActionForward;
import com.hk.dtos.UserDto;
import com.hk.service.LoginService;

public class RegisterAction implements Action{
	
	@Override
	public ActionForward execute(HttpServletRequest request,
			HttpServletResponse response) {
		LoginService manager=LoginService.getInstance();
		UserDto dto = new UserDto();
		HttpSession session = request.getSession();
/*
 * String name;
		String addr;
		String id;
		String pwd;
		String phone;
		String email;
		String birth;
		String photo;
		String propile;
		int score;
		int grade;
		Timestamp regdate;
 */
	    String id = request.getParameter("id");
	    String addr = request.getParameter("addr");
	    String name = request.getParameter("name");
	    String phone = request.getParameter("phone");
	    String pwd = request.getParameter("pw");
	    String email = request.getParameter("email");
	    String year = request.getParameter("year");
	    String month = request.getParameter("month");
	    String day = request.getParameter("day");
	    String propile = request.getParameter("propile");
	    String photo = request.getParameter("photo");
	    if(month.length()!=2){
	    	month = "0" + month;
	    }
	    if(day.length()!=2){
	    	day = "0" + day;
	    }
	    String birth = year + month + day;
	    
	    dto.setId(id);
	    dto.setAddr(addr);
	    dto.setName(name);
	    dto.setPhone(phone);
	    dto.setPwd(pwd);
	    dto.setPropile(propile);
	    dto.setBirth(birth);
	    dto.setEmail(email);
	    dto.setPhoto(photo);
	    dto.setScore(0);
	    dto.setGrade(9);
	    
	    boolean is = manager.register(dto);
	    
		ActionForward forword=new ActionForward();
		if(is){
		session.setAttribute("uid",dto);
		forword.setUrl("relogin");
		forword.setRedirect(false);
	    }
	
	return forword;
}//
}
